# $Id$
# Maintainer: Thomas Bächler <thomas@archlinux.org>

pkgname=bftpd
pkgver=4.5
pkgrel=1
pkgdesc="Small, easy-to-configure FTP server"
arch=(i686 x86_64)
url="http://bftpd.sourceforge.net/"
license=('GPL')
depends=('pam')
install=bftpd.install
backup=(etc/bftpd.conf
        etc/logrotate.d/bftpd
        etc/pam.d/bftpd
        etc/xinetd.d/bftpd)
source=(http://downloads.sourceforge.net/sourceforge/bftpd/bftpd-$pkgver.tar.gz
        bftpd.logrotate
        bftpd.pam
        bftpd.xinetd
        bftpd.service
        bftpd.socket
        bftpd_AT.service)
md5sums=('4ce6364f65eef1e7ed8ad6202eb89389'
         '853680dad0df39d0b4d2fb43d4be430a'
         '96f82c38f3f540b53f3e5144900acf17'
         '23feb84e8ecbae5df320b49e01821d9a'
         '94b483f7c7b65580a30ebc6a8fe80d1b'
         '93509ee83148160f60c009a2192a6774'
         'cb6a3334a7c8b5b8b559a643a65928c4')

build() {
  cd "${srcdir}"/$pkgname
  # The bftpd author keeps screwing up the release tarballs
  rm -f config.{cache,status}
  autoreconf
  sed 's|$(prefix)/sbin|$(prefix)/bin|g' -i Makefile.in
  ./configure --prefix=/usr \
              --enable-pam \
              --mandir=/usr/share/man \
              --sysconfdir=/etc \
  make
}

package() {
  cd "${srcdir}"/$pkgname
  install -d -m755 "${pkgdir}"/usr/{bin,share/man/man8}
  install -D -m644 "${srcdir}"/bftpd.logrotate "${pkgdir}"/etc/logrotate.d/bftpd
  make DESTDIR="${pkgdir}" install
  # Remove log file and /var/run from the package
  # This guy keeps messing up his Makefile, /usr/var, wtf?
  rm -f "${pkgdir}"/usr/var/log/bftpd.log
  rmdir "${pkgdir}"/usr/var/{run/bftpd,run,log,}
  # Install PAM file
  mkdir -p "${pkgdir}"/etc/pam.d
  cp "${srcdir}"/bftpd.pam "${pkgdir}"/etc/pam.d/bftpd
  # Install xinetd file
  install -D -m644 "${srcdir}"/bftpd.xinetd "${pkgdir}"/etc/xinetd.d/bftpd
  # Did I mention this guy keeps messing up his Makefiles?
  mv "${pkgdir}"/usr/etc/bftpd.conf "${pkgdir}"/etc/
  rmdir "${pkgdir}"/usr/etc
  # Fix default in config file
  sed 's|#ROOTDIR="/path/for/anonymous/user"|# bftpd interprets ROOTDIR="%h" (the default), as ROOTDIR="/" for the anonymous user, override it\n  ROOTDIR="/srv/ftp"|' -i "${pkgdir}"/etc/bftpd.conf
  # Install systemd files
  install -D -m644 "${srcdir}"/bftpd.service "${pkgdir}"/usr/lib/systemd/system/bftpd.service
  install -D -m644 "${srcdir}"/bftpd_AT.service "${pkgdir}"/usr/lib/systemd/system/bftpd@.service
  install -D -m644 "${srcdir}"/bftpd.socket "${pkgdir}"/usr/lib/systemd/system/bftpd.socket
}
